﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DC2010.Objects;
using DC2010;
using Microsoft.Xna.Framework.Graphics;
using RolePlaying;
using Microsoft.Xna.Framework;
using Xna.Base;
using DC2010.Objects.Data;

namespace DC2010
{
    public partial class Hud
    {

        private void DrawPlayerPanels()
        {
            SpriteBatch spriteBatch = screenManager.SpriteBatch;

            int PanelCount = Root.I.GameSystem.Party.MembersData.Count;

            for (int i = 1; i <= PanelCount; i++)
            {
                CreatureData c = Root.I.GameSystem.Party.GetCreatureByIndex(i);

                if (Root.I.GameSystem.SelectedMember == c)
                {
                    DrawPlayerPanelSelected(RM.Get("PlayerPanel" + i).GetVector(), c);
                }
                else
                {
                    DrawPlayerPanelHands(RM.Get("PlayerPanel" + i).GetVector(), c, i);
                }

                DrawPlayerBars(RM.Get("PlayerPanel" + i).GetVector(), c);


                DrawBuffs(RM.Get("PlayerPanel" + i).GetVector(), c);

            }
        }

        private void DrawPlayerBars(Vector2 position, CreatureData creature)
        {
            SpriteBatch spriteBatch = screenManager.SpriteBatch;

            float percentHealth = creature.Attributes.Health.Percent / 100;
            float percentStamina = creature.Attributes.Stamina.Percent / 100;
            float percentMana = creature.Attributes.Mana.Percent / 100;

            Texture2D t2d = TM.GetTex(creature.Gfx.Bar);
            int cHHealth = (int)(percentHealth * t2d.Height);
            int cHStamina = (int)(percentStamina * t2d.Height);
            int cHMana = (int)(percentMana * t2d.Height);

            Rectangle rHealth = new Rectangle();
            rHealth.Width = 8; rHealth.X = 0;
            rHealth.Y = 50 - cHHealth;
            rHealth.Height = cHHealth;

            Rectangle rStamina = new Rectangle();
            rStamina.Width = 8; rStamina.X = 0;
            rStamina.Y = 50 - cHStamina;
            rStamina.Height = cHStamina;

            Rectangle rMana = new Rectangle();
            rMana.Width = 8; rMana.X = 0;
            rMana.Y = 50 - cHMana;
            rMana.Height = cHMana;

            //draw health
            spriteBatch.Draw(t2d, position + new Vector2(92, 4 + rHealth.Y), rHealth, Color.White);
            spriteBatch.Draw(t2d, position + new Vector2(104, 4 + rStamina.Y), rStamina, Color.White);
            spriteBatch.Draw(t2d, position + new Vector2(116, 4 + rMana.Y), rMana, Color.White);
        }

        public void DrawPlayerPanelSelected(Vector2 position, CreatureData player)
        {
            SpriteBatch spriteBatch = screenManager.SpriteBatch;
            spriteBatch.Draw(TM.GetTex("Interface/PlayerPanelEmpty"), position, Color.White);
            spriteBatch.Draw(TM.GetTex(player.Gfx.Face), position + new Vector2(8, 0), Color.White);

        }

        public void DrawPlayerPanelHands(Vector2 position, CreatureData player, int playerNumber)
        {
            SpriteBatch spriteBatch = screenManager.SpriteBatch;
            spriteBatch.Draw(TM.GetTex("Interface/PlayerPanelHands"), position, Color.White);
            spriteBatch.DrawString(Fonts.DebugFont, player.ShortName.ToUpper(), position + new Vector2(2, 2), Tools.GetColor(player.Gfx.Color));

            ////..
            ItemData iLeft = player.Inventory.GetItemAtPosition(CarryLocations.LeftHand).GetItemDataFromCode();
            ItemData iRight = player.Inventory.GetItemAtPosition(CarryLocations.RightHand).GetItemDataFromCode();

            if (iRight != null)
            {
                if (player.ActionOptionsAreDisplayed_Right)
                    spriteBatch.Draw(TM.GetTex("Interface/Box/BoxAqua"), RM.Get("PlayerPanel" + playerNumber + "_Hand_Right").GetVector() + new Vector2(-2, -2), Color.White);

                TM.GetAnimation(iRight.Gfx.Icon.Texture).Draw(spriteBatch, RM.Get("PlayerPanel" + playerNumber + "_Hand_Right").GetVector(), 0f, Color.White);
            }

            if (iLeft != null)
            {
                if (player.ActionOptionsAreDisplayed_Left)
                    spriteBatch.Draw(TM.GetTex("Interface/Box/BoxAqua"), RM.Get("PlayerPanel" + playerNumber + "_Hand_Left").GetVector() + new Vector2(-2, -2), Color.White);

                TM.GetAnimation(iRight.Gfx.Icon.Texture).Draw(spriteBatch, RM.Get("PlayerPanel" + playerNumber + "_Hand_Left").GetVector(), 0f, Color.White);
            }
        }

    }
}
